package com.mars.tukuan.rpc.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mars.base.common.exception.AppException;
import com.mars.base.common.utils.Paginator;
import com.mars.base.service.support.BaseService;
import com.mars.tukuan.dao.mapper.CarCheckMapper;
import com.mars.tukuan.dto.CarCheckVo;
import com.mars.tukuan.entity.CarCheck;
import com.mars.tukuan.rpc.api.CarCheckService;
import com.mars.tukuan.rpc.api.CarStateService;

@Service
public class CarCheckServiceImpl extends BaseService<CarCheck, Long> implements CarCheckService {
	
	@Autowired
	private CarCheckMapper mapper;
	
	@Autowired
	private CarStateService carStateService ;
	
	@Override
	public int deleteByIds(String ids) throws AppException {
		//删除关联的数据
		String[] split = ids.split(",") ;
		for (String carCheckId : split) {
			this.carStateService.deleteByCheckId(Long.parseLong(carCheckId));
		}
		
		return super.deleteByIds(ids);
	}

	@Override
	public PageInfo<CarCheckVo> list(Paginator paginator, CarCheckVo entity) {
		PageHelper.startPage(paginator.getPage(), paginator.getRows()) ;
		Page<CarCheckVo> page = this.mapper.list(paginator, entity) ;
		
		return new PageInfo<CarCheckVo>(page) ;
	}

	@Transactional
	@Override
	public int insertHandler(CarCheckVo vo) {
		this.mapper.insertSelective(vo) ;
		return vo.getId().intValue();
	}
	
}
